package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xmy.cultivate.entity.request.AiSitePc;
import com.xmy.cultivate.entity.views.AiSitePcLoginRs;
import com.xmy.cultivate.feign.english.IFeiEnglishFeignClient;
import com.xmy.cultivate.service.IStudentService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("/api/aiSitePc")
public class AiSitePcController extends BaseController{

    @Autowired
    IFeiEnglishFeignClient iFeiEnglishFeignClient;

    @Autowired
    IStudentService iStudentService;

    @GetMapping("/getSitePcForStudent")
    public Result getSitePcForStudent(@RequestParam("studentId") Long studentId,
                                      @RequestParam(value = "markCode",required = false) String markCode
    ){
        AiSitePcLoginRs aiSitePcLoginRs = null;
        try {
            aiSitePcLoginRs = iFeiEnglishFeignClient.getSitePcForStudent(studentId,markCode);
            if (!Objects.isNull(aiSitePcLoginRs)) {
                if (aiSitePcLoginRs.getStudentId()!=null){
                    String studentName = iStudentService.getStudentName(aiSitePcLoginRs.getStudentId());
                    aiSitePcLoginRs.setStudentName(studentName);
                }
            }
        }catch (Exception e){}

        return new Result(Code.OK,aiSitePcLoginRs,"");
    }
}
